Skip to content

fix: use dynamic import in tests to prevent ESM hoisting race#429

Merged
paulo-ferraz-oliveira merged 1 commit intoerlef:mainfrom
petermm:fix/test-esm-import-hoisting
Mar 13, 2026
Merged

fix: use dynamic import in tests to prevent ESM hoisting race#429
paulo-ferraz-oliveira merged 1 commit intoerlef:mainfrom
petermm:fix/test-esm-import-hoisting

Conversation

@petermm
Copy link
Contributor

@petermm petermm commented Mar 12, 2026

Static ESM imports are hoisted above top-level statements, causing setup-beam.js to evaluate its main() guard before process.env.NODE_ENV is set to 'test'. This triggered core.setFailed() during module load, setting process.exitCode=1 and failing the test file even though all individual test cases passed.

Switch setup-beam.js to a dynamic await import() so that the env and input setup runs first, ensuring the NODE_ENV='test' guard works correctly.

Description

Running npm test would fail.

Static ESM imports are hoisted above top-level statements, causing
setup-beam.js to evaluate its main() guard before process.env.NODE_ENV
is set to 'test'. This triggered core.setFailed() during module load,
setting process.exitCode=1 and failing the test file even though all
individual test cases passed.

Switch setup-beam.js to a dynamic await import() so that the env and
input setup runs first, ensuring the NODE_ENV='test' guard works
correctly.

Amp-Thread-ID: https://ampcode.com/threads/T-019ce36a-a18f-7494-ac0a-c094a84f06ad
Co-authored-by: Amp <amp@ampcode.com>
@paulo-ferraz-oliveira
Copy link
Collaborator

Good stuff. Yeah, thanks. As with the other ones, ping me if I don't do something about this tomorrow or at most Monday. CI's now running...

@paulo-ferraz-oliveira
Copy link
Collaborator

Merging as CI's good and I have no further comments. Thanks.

@paulo-ferraz-oliveira paulo-ferraz-oliveira merged commit f018c1e into erlef:main Mar 13, 2026
71 checks passed
@petermm petermm deleted the fix/test-esm-import-hoisting branch March 14, 2026 00:08
@paulo-ferraz-oliveira
Copy link
Collaborator

This was published in v1.23.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants